package com.navinfo.platform.bigdata.dto;

import com.navinfo.platform.bigdata.util.EntityConvert;
import com.navinfo.stream.qingqi.protocol.java.LCStatusType;
import com.navinfo.stream.qingqi.protocol.java.LCVehicleStatusData;
import com.navinfo.stream.qingqi.protocol.java.LCVehicleStatusData.VehicleStatusData;

import java.util.ArrayList;
import java.util.List;

public class VehicleStatusAdditionDto {

    private String types;
    private long statusValue;

    public String getTypes() {
        return types;
    }
    public void setTypes(String types) {
        this.types = types;
    }
    public long getStatusValue() {
        return statusValue;
    }
    public void setStatusValue(long statusValue) {
        this.statusValue = statusValue;
    }

    public static VehicleStatusAdditionDto parseProto(LCVehicleStatusData.VehicleStatusData vehicleStatusData) {
        VehicleStatusAdditionDto vehicleStatusAdditionDto = new VehicleStatusAdditionDto();
        vehicleStatusAdditionDto.setStatusValue(vehicleStatusData.getStatusValue());
        vehicleStatusAdditionDto.setTypes(vehicleStatusData.getTypes().name());
        List<String> dataList = new ArrayList<String>();
        dataList.add(vehicleStatusData.getTypes().name()+ ":" + vehicleStatusData.getStatusValue());
        return vehicleStatusAdditionDto;
    }

    /**
     * 解析成String拼接字符串
     * @param vehicleStatusData
     * @return
     */
    public static String parseString(VehicleStatusData vehicleStatusData) {
        return EntityConvert.convert(vehicleStatusData.getTypes().getNumber(), vehicleStatusData.getStatusValue());
    }
    /**
     * 反解析成PB对象
     * @param str
     * @return
     */
    public static VehicleStatusData parsePB(String str){
        VehicleStatusData.Builder builder = null;
        try{
            String[] revert = EntityConvert.revert(str);
            if(null!=revert && revert.length>=2){
                builder = VehicleStatusData.newBuilder();
                builder.setTypes(LCStatusType.StatusType.valueOf(Integer.valueOf(revert[0])));
                builder.setStatusValue(Long.valueOf(revert[1]));
            }
        }catch (Exception e){
            e.printStackTrace();
        }

        return builder==null? null : builder.build();
    }


}
